<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <title>Title</title>
    <link rel="icon" href="${pageContext.request.contextPath}/static/img/favicon.ico"  type="image/x-icon" />
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<jsp:include page="page.jsp"></jsp:include>
<form action="/user/login" method="post" class="form-horizontal" role="form" >
    <div class="form-group">
        <label for="firstname" class="col-sm-2 control-label">名字</label>
        <div class="col-sm-10">
            <input name="username" type="text" value="${cookie.username.value}" class="form-control" id="firstname"
                   placeholder="账号">
        </div>
    </div>
    <div class="form-group">
        <label for="lastname" class="col-sm-2 control-label">密码</label>
        <div class="col-sm-10">
            <input name="password" type="text" value="${cookie.password.value}" class="form-control" id="lastname"
                   placeholder="密码">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <div class="checkbox">
                <label>
                    <input name="remember" type="checkbox" value="1"  ${cookie.remember.value!=null?'checked':''}> 记住我
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">登录</button>
        </div>
    </div>
</form>

<h3>注册新用户</h3>
<form action="/user/register"  method="post" class="form-horizontal" role="form" >
    <div class="form-group">
        <label for="firstname" class="col-sm-2 control-label">名字</label>
        <div class="col-sm-10">
            <input name="username" type="text" value="" class="form-control"
                   placeholder="账号">
        </div>
    </div>
    <div class="form-group">
        <label for="lastname" class="col-sm-2 control-label">密码</label>
        <div class="col-sm-10">
            <input name="password" type="text" value="" class="form-control"
                   placeholder="密码">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">注册</button>
        </div>
    </div>
</form>
<%--<form action="/user/login" method="post">--%>
<%--   账号 <input name="username" type="text" value="${cookie.username.value}">--%>
<%--   密码 <input name="password" type="text" value="${cookie.password.value}">--%>
<%--    记住密码<input name="remember" type="checkbox" value="1"  ${cookie.remember.value!=null?'checked':''}>--%>
<%--   ${cookie.remember.value} <input type="submit">--%>
<%--</form>--%>
<%--<form action="/user/register" method="get">--%>
<%--    <input name="username" type="text">--%>
<%--    <input name="password" type="text">--%>
<%--    注册<input type="submit">--%>
<%--</form>--%>
<h3>手机验证码登录</h3>
<form action="/user/login" method="post" id="form" class="form-horizontal" role="form" >
    <input type="hidden" name="_method" value="PUT">
    <input type="hidden" name="codehide" value="" id="code">
    <div class="form-group">
        <label for="firstname" class="col-sm-2 control-label">名字</label>
        <div class="col-sm-10">
            <input  name="phonenum" type="text" id="phone" type="text" value="" class="form-control"
                   placeholder="手机号">
        </div>
    </div>
    发送验证码<input type="button" id="sub" value="发送验证">
    <div class="form-group">
        <label for="lastname" class="col-sm-2 control-label">验证码</label>
        <div class="col-sm-10">
            <input name="code" id="codehide" type="text" value="" class="form-control"
                   placeholder="验证码">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="tijiao" value="提交" class="btn btn-default">提交</button>
        </div>
    </div>
</form>
<a href="/user/loginbyphone">phone</a>
<%--<form action="/user/logins" method="post" id="form">--%>
<%--    <h3>手机号码快速登录</h3>--%>
<%--    <input type="hidden" name="codehide" value="" id="code">--%>
<%--    请输入验证手机号<input name="phonenum" type="text" id="phone">--%>
<%--    发送验证码<input type="button" id="sub" value="发送验证">--%>
<%--    验证码<input type="text" name="code" id="codehide">--%>
<%--    登录<input type="button" id="tijiao" value="提交">--%>
<%--</form>--%>
错误信息:${error}
<script>
   //生成6位数随机数
    function num(){
        var mm=Math.random();
        var six = "";
        if(mm>0.1)
        {
            six=Math.round(mm*1000000);
        }else{
            mm += 0.1;
            six = Math.round(mm*1000000);
        }
        return six;
    }

    $("#sub").click(function () {
        //生成验证码
        var code=num();
        alert(code);
       var phone=$("#phone").val();
        var data={"code":code,"phonenum":phone};
        $.ajax({
            url:"/user/code",
            type : "post",
            dataType : "json",
            data: JSON.stringify(data),
            contentType: "application/json",
            success:function (data) {
                if(data.flag=='true'){
                    $("#code").val(code);
                    layer.msg('验证码已发送');
                }else{
                    layer.msg('手机验证失败', function(){
                    });
                }
            }
        })
    })

    $("#tijiao").click(function () {
       var codehide=$("#codehide").val();
        var code=$("#code").val();
        if(code==codehide){
            $("#form").submit();
        }else{
            layer.msg('验证码错误', function(){
            });
        }

    })



</script>
</body>
</html>
